﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DotNet.Business;
using System.Collections.Generic;
using System.Text;

public partial class admin_addProduct :basePage
{
    #region 初始化变量
    tab_productBll productBll = new tab_productBll();
    tab_productClassBll productClassBll = new tab_productClassBll();
    StringBuilder sb = new StringBuilder();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            if (Request.QueryString["action"]!=null)
            {
                string action = Request.QueryString["action"];
                switch (action.Trim())
                {
                    case"insert":
                        addProduct();
                        break;
                    default:
                        break;
                }
                
            }
        }
    }
    #region 添加产品信息
    /// <summary>
    /// 添加产品信息
    /// </summary>
    public void addProduct() 
    {
        tab_product p = new tab_product();
        p.productName = Request.Form["txt_productName"].ToString();
        if (p.productName.Trim()=="")
        {
            Response.Write("没有添加产品名称！");
            Response.End(); 
        }
        p.productInfo =Server.HtmlDecode(Request.Form["FCKeditor1"].ToString());
        p.productTitle = Request.Form["txt_title"].ToString();
        p.productDescription = Request.Form["txt_seoDescription"].ToString();
        p.productKey = Request.Form["txt_key"].ToString();
        p.createDate = DateTime.Now;
        p.pcid =Convert.ToInt32(Request.Form["sel_productClass"]);
        if (p.pcid<=0)
        {
            Response.Write("没有选择产品类别！");
            Response.End(); 
        }
        if (productBll.Insert(p))
        {
            Response.Write("1");
            Response.End();
        }
        else
        {
            Response.Write("生成失败!");
            Response.End(); 
        }               
    }
    #endregion

    #region 产品类别
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string ProductClassSelect() 
    {
        IList<tab_productClass> Ilist_ProductClass = productClassBll.GetModel();
        foreach (tab_productClass productClass in Ilist_ProductClass)
        {
            sb.AppendFormat("<option value='{0}'>{1}</option>",productClass.pcid,productClass.productClassName);
        }
        return sb.ToString();
    }
    #endregion
}
